package main.java.indi.zyj.c150.dps;

import java.util.Scanner;


/**
        w....#.g
 */
public class _06_SearchHoney {



    static int m = 0, n = 0;
    static Character[][] maze = new Character[100][100];
    static boolean[][][] visited = new boolean[100][100][2];


    static void Dfs(int x, int y, int stepManner){
        if (x<0 || x>=m || y<0 || y>=n || visited[x][y][stepManner] || maze[x][y] == '#'){
            return;
        }
        visited[x][y][stepManner] = true;
        Dfs(x-(2-stepManner), y, stepManner);
        Dfs(x, y-(2-stepManner), stepManner);
        Dfs(x+(2-stepManner), y, stepManner);
        Dfs(x, y+(2-stepManner), stepManner);
    }



    public static void main(String[] args) {

        int princeX = 0, princeY = 0, princessX = 0, princessY = 0;
        boolean ans = false;
        Scanner scan = new Scanner(System.in);

        System.out.println("请输入迷宫的大小：");
        m = scan.nextInt();
        n = scan.nextInt();

        System.out.println("请输入迷宫的地图：");
        for (int i = 0; i < m; i++) {
            String s = scan.next();
            for (int j = 0; j < n; j++) {
                maze[i][j] = s.charAt(j);
            }
        }

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (maze[i][j] == 'w'){
                    princeX = i;
                    princeY = j;
                }
                if (maze[i][j] == 'g'){
                    princessX = i;
                    princessY = j;
                }
            }
        }

        Dfs(princeX, princeY, 0);
        Dfs(princessX, princessY, 1);

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (visited[i][j][0] && visited[i][j][0]){
                    ans = true;
                }
            }
        }

        if (ans){
            System.out.println("Yes!");
        }else {
            System.out.println("No!");
        }

    }




}
